// ignore_for_file: prefer_interpolation_to_compose_strings, unnecessary_string_interpolations
import 'package:flutter_kit_plus/flutter_kit.dart';

import '../home/blue_data_model.dart';

const write_service = 'FFD5';
const write_uuid = 'FFD9';

const read_service = 'FFD0';
const read_uuid = 'FFD4';

const ble_on_off = 0xDD;
const ble_sigle_color = 0xB6;
const ble_music_mode = 0x78;
const ble_color_mode = 0x2A;
const ble_mic_mode = 0x01;
const ble_get_data = 0x7F0177;

class SendData {
  static List<int> getBytes(String tag, var data) {
    List<int> bytes = [];
    switch (tag) {
      case '开关':
        bool ison = data;
        bytes += ble_on_off.bytes;
        bytes += ison ? [0x23] : [0x24];
        bytes += [0x33];
      case '单色模式':
        List<int> colors = data;
        bytes += ble_sigle_color.bytes;
        bytes += colors;
        bytes += [0x00];
        bytes += [0xF0];
        bytes += [0xAA];
      case '指定颜色模式':
        DataModel model = data;
        bytes += ble_color_mode.bytes;
        bytes += model.mode.bytes;
        bytes += model.speed.bytes;
        bytes += [0x44];
      case '麦克风':
        bool ison = data;
        bytes += ble_mic_mode.bytes;
        bytes += ison ? [0xF0] : [0x0F];
        bytes += [0x00, 0x00];
        bytes += [0x00, 0x18];
      case '查询数据':
        bytes = [0x7F, 0x01, 0x77];
      default:
        break;
    }
    return bytes;
  }

  static void send(String tag, var data) {
    List<int> bytes = getBytes(tag, data);
    print('自定义的类， 发送数据 = ${bytes.toHexstr(' |')}');
    if (bytes.isEmpty) {
      return;
    }
    BluetoothManager.instance.write(
        data: bytes,
        service_uuid: write_service,
        characteristics_uuid: write_uuid);
  }
}
